package com.example.boardroom.newItems;

import android.view.View;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.entity.node.BaseNode;
import com.chad.library.adapter.base.provider.BaseNodeProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.boardroom.R;

import java.util.List;
import java.util.Objects;

public class RootNodeProvider extends BaseNodeProvider {
    @Override
    public int getItemViewType() {
        return 0;
    }

    @Override
    public int getLayoutId() {
        return R.layout.def_section_head;

    }

    @Override
    public void convert(@NonNull BaseViewHolder holder, BaseNode data) {
        FirstNode bean = (FirstNode) data;
        holder.setText(R.id.tv_device_name, bean.dataDTO.deviceName);
        holder.setText(R.id.tv_device_isLine, bean.dataDTO.deviceName);
        holder.setText(R.id.tv_device_open, bean.dataDTO.openStatus.equals("1") ? "开启" : "关闭");
        holder.setTextColor(R.id.tv_device_open, bean.dataDTO.openStatus.equals("1")? context.getResources().getColor(R.color.holo_green_light):context.getResources().getColor(R.color.holo_red_light));
    }

    @Override
    public void onClick(@NonNull BaseViewHolder helper, @NonNull View view, BaseNode data, int position) {
        super.onClick(helper, view, data, position);
        LogUtils.i("lufei_node_1", "当前节点:" + position , "总长度:" + getAdapter().getData().size(),data.getChildNode(),data.getChildNode().size());



        if (data.getChildNode().size()<=0){
            ToastUtils.showShort("没有控制功能");
        }else {
            ToastUtils.cancel();
        }
            Objects.requireNonNull(getAdapter()).expandOrCollapse(position);
    }
}
